#ifndef MUSICPAGE_H
#define MUSICPAGE_H

#include <QAbstractTableModel>
#include <ElaScrollPage.h>
#include <word_engine.h>

class ElaComboBox;
class ElaLineEdit;
class ElaTableView;
class ElaProgressBar;
class ElaText;
class MusicApi;
class waitPage;
class WordExport;

class ElaTableViewModel : public QAbstractTableModel
{
    Q_OBJECT
public:

    ElaTableViewModel(QObject* parent = nullptr);
    ~ElaTableViewModel();
    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    int columnCount(const QModelIndex& parent = QModelIndex()) const override;
    QVariant data(const QModelIndex& index, int role) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    void setHeader();
    void setSongsList(const QVector<QVector<QString>> &songsList);
    void setIconLIst(const QString &pictureLink);
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

private:
    QStringList header_;
    QList<QStringList> dataList_;
    QList<QIcon> iconList_;
};


class musicPage : public ElaScrollPage
{
    Q_OBJECT
public:
    musicPage(QWidget *parent = nullptr);
    ~musicPage();

protected:
    virtual void resizeEvent(QResizeEvent *event);

private slots:
    void onImportButtomClicked();
    void onExportButtonClicked();
    void onErrorOccurred(QString error);
    void onSongsNumberChanged(int totalNum, int currNum);
    void ontaskFinished();
    void onClicked(QModelIndex index);
    void onTranslateLyric(bool check);
    void onRTranslateLyric(bool check);

private:
    ElaComboBox *musicPlatform_{nullptr};
    ElaLineEdit *playlistLink_{nullptr};
    ElaTableView *songList_{nullptr};
    ElaTableViewModel *songListModel_{nullptr};
    ElaProgressBar *importProgress_{nullptr};
    ElaText *importProgressText_{nullptr};
    QWidget *centerWidget_{nullptr};
    waitPage *waitPage_{nullptr};
    WordExport *word_{nullptr};
    QThread *wordThread_{nullptr};

    MusicApi *musicApi_{nullptr};

    bool showTranslate = false;
    bool showRTranslate = false;
};

#endif // MUSICPAGE_H
